var backalert = '<div class="alert alert-warning text-center"><button type="button" class="close" data-dismiss="alert"><span aria-hidden="true">&times;</span><span class="sr-only">Close</span></button>';
//点击注册验证
function register_vel(){
	var username,email,password,repassword;
  	username = $("#register-username").val();
	var targetusername = $(".alert-username");
	if(!username_vel(username,targetusername)){
		return false;
	};	
	//邮箱验证
	email =$("#register-email").val();
	var targetemail = $(".alert-email");
	if(!email_vel(email,targetemail)){
		return false;
	}
	//密码验证
	password = $("#register-password").val();
	repassword =$("#re-register-password").val();
	var targetpassword = $(".alert-password");
	var targetrepassword = $(".alert-repassword");
	if(!password_vel(password,repassword,targetpassword,targetrepassword)){
		return false;
	}
	return true;
}
//用户名验证
function username_vel(username,target){
	var info;
	var usernametype=/^[a-zA-Z0-9_-]+$/;
	var usernameheader = /^[a-z]+/;
	try{
			if(username == ""){
				throw '用户名不能为空';
			}else if (username.length>=15 || username.length<4){
				throw '用户名长度不能小于4字符或大于15字符';
			}else if(!usernametype.test(username)) {
				throw '用户名必须是字母或字母加数字';
			}else if(!usernameheader.test(username)){
				throw '用户名必须是字母开头';
			}else{
				target.html("");
			}
	}
	catch(e) {
			target.html(backalert+e+"</div>");
			return false;
	}
	return true;
}
//邮箱验证
function email_vel(email,target){
	var emailtype=/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
		try{
			if(email == "") {
				throw '邮箱不能为空';
			}else if(!emailtype.test(email)) {
				throw '邮箱格式不正确';
			}else{
				target.html("");
			}
		}
		catch(e){
			alert2000(target,e);
			return false;
		}
		return true;	
}
//密码和重复密码验证
function password_vel(password,repassword,target,targetre){
	var info;
	var passwordtype1 = /^[0-9]+$/;
	var passwordtype2 = /^[a-z]+$/;
	var passwordtype3 = /^[A-Z]+$/;
	var rightpassword;
		try{
			if(password.length<8) {
				throw '密码长度不能小于8';
			}else if (passwordtype1.test(password)) {
				throw '密码不能为纯数字';
			}else if (passwordtype2.test(password)) {
				throw '密码不能为纯小写字母';
			}else if(passwordtype3.test(password)) {
				throw '密码不能为纯大写字母';
			}else{
				rightpassword = password;
				target.html("");
				if(repassword == rightpassword){
					targetre.html("");
				}
			}		
	//重复密码验证
			if(repassword){
				if(rightpassword){
					if(repassword != rightpassword){
						throw '两次输入密码不一致';
					}else{
						targetre.html("");
					};
				};
			}
		}
		catch(e) {
				target.html(backalert+e+"</div>");
				return false;
		}
		return true;
}
//几秒后跳转
function countDown(secs,url,target) {
	target.html(backalert+secs+"秒后跳转！</div>");
	if(--secs>0) {
		setTimeout(function(){
			countDown(secs,url,target);
		},1000);
	}else{
			location.href = url;
		
	}
}
//点眼睛重置密码
function eyetoggle($eye,$target) {
	$eye.on("mousedown",function(){
		$target.attr("type","text");
	});
	$eye.on("mouseup",function(){
		$target.attr("type","password");
	});
}




